package com.meirengu.webview.controller;

import com.meirengu.common.StatusCode;
import com.meirengu.model.Result;
import com.meirengu.webview.service.UserInfoService;
import com.meirengu.webview.service.UserService;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * ${DESCRIPTION}
 *
 * @author Mao
 * @create 2017-05-24 15:58
 */
@Controller
@RequestMapping("userInfo")
public class UserInfoController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(UserInfoController.class);

    @Autowired
    UserService userService;

    @Autowired
    UserInfoService userInfoService;

    @ResponseBody
    @RequestMapping(value = "complement", method = RequestMethod.POST)
    public Result complement(HttpServletRequest request) {
        try {
            userInfoService.complement(request);
            return super.setResult(StatusCode.OK, "", StatusCode.codeMsgMap.get(StatusCode.OK));
        } catch (Exception e) {
            e.printStackTrace();
            String param = String.format("参数:params:%s", request.getParameter("p"));
            logger.error(">> UserInfoController.complement throw exception: {} happens. params:{}.", ExceptionUtils.getFullStackTrace(e), param);
            return super.setResult(StatusCode.INTERNAL_SERVER_ERROR, "", StatusCode.codeMsgMap.get(StatusCode.INTERNAL_SERVER_ERROR));
        }

    }
}
